#pragma once

#include "cybertron/node/BaseApp.hpp"
#include "TaskManager.hpp"
#include "NodeAgentManger.hpp"
#include "NodeCommanderManger.hpp"
#include "cybertron/node/TaskRunnerPoolClient.hpp"
#include <iostream>

class MasterServer;

#define theApp GET_APP_INSTANCE(TheApp)

class TheApp : public cybertron::BaseApp
{
public:
	TheApp();



	std::shared_ptr<MasterServer> getCoordinatorServer() { return mMasterServer; }
	TaskManager* getTaskManager() { return &mTaskManager; }
	NodeAgentManger* getNodeAgentManger() { return &mNodeAgentManger; }
	CommanderNodeManger* getConsolePool() { return &mConsolePool; }

	void InitNodeInfo();
	void taskPreAllocate(string taskId);
	void taskStart(string taskId);
	void taskStop(string taskId);
protected:

	int parseArguments(int argc, char* argv[]);
	void getVerion();
	int beforeRun();
	int run();
	int checkStateThread();

	std::shared_ptr<MasterServer> mMasterServer;
	TaskManager mTaskManager;
	
	NodeAgentManger mNodeAgentManger;
	CommanderNodeManger mConsolePool;
	int mListenPort;

	TaskRunnerPoolClient mTaskRunnerPoolClient;
	std::string mGroupId;
	Common::EWorkNodeType mType;
	std::string mId;
	std::string mDescription;
	std::string mUserData;
	std::string mTag;
};
